package com.compare.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.compare.service.CompareService;
import com.config.entity.LineConfig;
import com.config.service.LineConfigService;

@RequestMapping("/compare")
@Controller
public class CompareController {

	@Resource(name="compareService")
	private CompareService compareService;
	@Resource(name="lineConfigService")
	private LineConfigService lineConfigService;
	
	
	/**
	 * 电度电费对比
	 * @param model
	 * @param type
	 * @return
	 */
	@RequestMapping("/electricity/{type}")
	public String electricitycompareAnalysis(Model model,@PathVariable(value = "type") String type){
		model.addAttribute("currentName","整线电度电费比对分析");
		if(type.equals("day")){//日
			return "compare/electricity/electricityday";
		}else if(type.equals("complex")){//日综合
			return "compare/electricity/electricitycomplex";
		}else if(type.equals("week")){//周
			return "compare/electricity/electricityweek";
		}else{
			return "compare/electricity/electricitymonth";
		}
	}
	
	@RequestMapping("/electricitycompare/{type}")
	public Map<String, Object> compareElectricityData(@PathVariable(value = "type") String type,int lineId,
			@RequestParam(value="belongTime",required=false,defaultValue="0")String belongTime,
			@RequestParam(value="belongYear",required=false,defaultValue="0")int belongYear,
			@RequestParam(value="startDate",required=false,defaultValue="0")String startDate,
			@RequestParam(value="endDate",required=false,defaultValue="0")String endDate,
			@RequestParam(value="start",required=false,defaultValue="0")int start,
			@RequestParam(value="end",required=false,defaultValue="0")int end){
		Map<String, Object> model=new HashMap<String, Object>();
		if(lineId==0){
			LineConfig line=lineConfigService.findFirstLine();
			lineId=line.getId();
		}
		if(type.equals("day")){
			compareService.getEleChargeCompareDayData(lineId, belongTime, model);
		}else if(type.equals("complex")){
			compareService.getEleChargeCompareCompositeData(lineId, startDate,endDate, model);
		}else if(type.equals("week")){
			compareService.getEleChargeCompareWeekData(lineId, belongYear, start,end, model);
		}else{
			compareService.getEleChargeCompareMonthData(lineId, belongYear, start,end, model);
		}
		return model;
	}
	/**
	 * 开动率对比
	 * @param model
	 * @param type
	 * @return
	 */
	@RequestMapping("/startrate/{type}")
	public String startratecompareAnalysis(Model model,@PathVariable(value = "type") String type){
		model.addAttribute("currentName","整线开动率比对分析");
		if(type.equals("day")){//日
			return "compare/startrate/startrateday";
		}else if(type.equals("complex")){//日综合
			return "compare/startrate/startratecomplex";
		}else if(type.equals("week")){//周
			return "compare/startrate/startrateweek";
		}else{
			return "compare/startrate/startratemonth";
		}
	}
	
	@RequestMapping("/startratecompare/{type}")
	public Map<String, Object> compareStartrateData(@PathVariable(value = "type") String type,int lineId,
			@RequestParam(value="belongTime",required=false,defaultValue="0")String belongTime,
			@RequestParam(value="belongYear",required=false,defaultValue="0")int belongYear,
			@RequestParam(value="startDate",required=false,defaultValue="0")String startDate,
			@RequestParam(value="endDate",required=false,defaultValue="0")String endDate,
			@RequestParam(value="start",required=false,defaultValue="0")int start,
			@RequestParam(value="end",required=false,defaultValue="0")int end){
		Map<String, Object> model=new HashMap<String, Object>();
		if(lineId==0){
			LineConfig line=lineConfigService.findFirstLine();
			lineId=line.getId();
		}
		if(type.equals("day")){
			compareService.getStartRateCompareDayData(lineId, belongTime, model);
		}else if(type.equals("complex")){
			compareService.getStartRateCompareCompositeData(lineId, startDate,endDate, model);
		}else if(type.equals("week")){
			compareService.getStartRateCompareWeekData(lineId, belongYear, start,end, model);
		}else{
			compareService.getStartRateCompareMonthData(lineId, belongYear, start,end, model);
		}
		return model;
	}
	
	/**
	 * 超载对比
	 * @param model
	 * @param type
	 * @return
	 */
	@RequestMapping("/overload/{type}")
	public String overloadcompareAnalysis(Model model,@PathVariable(value = "type") String type){
		model.addAttribute("currentName","整线超载比对分析");
		if(type.equals("day")){//日
			return "compare/overload/overday";
		}else if(type.equals("complex")){//日综合
			return "compare/overload/overcomplex";
		}else if(type.equals("week")){//周
			return "compare/overload/overweek";
		}else{
			return "compare/overload/overmonth";
		}
	}
	
	
	@RequestMapping("/overloadcompare/{type}")
	public Map<String, Object> compareOverData(@PathVariable(value = "type") String type,int lineId,
			@RequestParam(value="belongTime",required=false,defaultValue="0")String belongTime,
			@RequestParam(value="belongYear",required=false,defaultValue="0")int belongYear,
			@RequestParam(value="startDate",required=false,defaultValue="0")String startDate,
			@RequestParam(value="endDate",required=false,defaultValue="0")String endDate,
			@RequestParam(value="start",required=false,defaultValue="0")int start,
			@RequestParam(value="end",required=false,defaultValue="0")int end){
		Map<String, Object> model=new HashMap<String, Object>();
		if(lineId==0){
			LineConfig line=lineConfigService.findFirstLine();
			lineId=line.getId();
		}
		if(type.equals("day")){
			compareService.getOverLoadComparaDayData(lineId, belongTime, model);
		}else if(type.equals("complex")){
			compareService.getOverLoadCompareCompositeData(lineId, startDate,endDate, model);
		}else if(type.equals("week")){
			compareService.getOverLoadComparaWeekData(lineId, belongYear, start,end, model);
		}else{
			compareService.getOverLoadCompareMonthData(lineId, belongYear, start,end, model);
		}
		return model;
	}
	
}
